@isTest

private class testHospital {
    
   
     static testMethod void testhospitalTrigger() {
         String rtid;
        Profile p  = [select id from profile where name=: 'System Administrator'];       
        User u1 =new User (alias = 'standt', email = 'shlia@isoftstone.com', emailencodingkey='UTF-8', lastname = 'Testing', languagelocalekey = 'en_US', localesidkey='en_US', profileid = p.id, timezonesidkey = 'Asia/Shanghai', username='standarduser@testorg1.com');
        insert u1;
         User u2 =new User (alias = 'new', email = 'shlia@isoftstone.com', emailencodingkey='UTF-8', lastname = 'Testing', languagelocalekey = 'en_US', localesidkey='en_US', profileid = p.id, timezonesidkey = 'Asia/Shanghai', username='new@testorg1.com');
        insert u2;
        
        system.runas(u1){
//test InsertHospitalChangeHistory ;  
            //insert hospital;
            hospital__c hp1=new hospital__c(name='testhospital',nickname__c='nickhp',approvaltype__c='新增医院',approvalstatus__c='等待审批');
            insert hp1;
            HCP__c hcp11=new hcp__c();
            hcp11.name='testhcp';
            hcp11.Hospital__c=hp1.id;
            hcp11.class2__c='决策人(DM)';
            hcp11.active__c=true;
            hcp11.approvalstatus__c='';
            hcp11.approvaltype__c = '';
            insert hcp11;
            
            hospital_approve__c hcpa=[select id,approvalstatus__c,effectivedate__c,approvaltype__c from hospital_approve__c where hospital__c=:hp1.id];
            
            hp1.effectivedate__c=date.today()+5;
            update hp1;
  //          hp1=[select id,approvalstatus__c from hospital__c where id=:hp1.id];
   //         system.assert(hp1.approvalstatus__c=='审批通过但未生效',hp1.approvalstatus__c);
            hp1.approvalstatus__c='审批通过';
            update hp1;
          hp1=[select id,active__c from hospital__c where id=:hp1.id];
 //           system.assert(hp1.active__c==true,hp1.active__c);
            
            //hospital rename;
            hcpa.approvalstatus__c='等待审批';
            hcpa.approvaltype__c='医院重命名';
            hcpa.namechangeto__c='newname';
            update hcpa;
            
            hcpa.effectivedate__c=date.today()+6;
            update hcpa;
    //        hp1=[select id,approvalstatus__c from hospital__c where id=:hp1.id];
   //         system.assert(hp1.approvalstatus__c=='审批通过但未生效',hp1.approvalstatus__c);
            hcpa.approvalstatus__c='审批通过';
            update hcpa;
    //       hp1=[select id,name from hospital__c where id=:hp1.id];
    //       system.assert(hp1.name=='newname',hp1.name);
            
           //hospital change class;
            hp1.approvalstatus__c='等待审批';
            hcpa.approvaltype__c='改变医院级别';
            hcpa.classchangeto__c='关键';
            update hp1;//reset hospital;
            update hcpa;
            
            hp1.effectivedate__c=date.today()+4;
          //  update hp1;
   //         hp1=[select id,approvalstatus__c from hospital__c where id=:hp1.id];
  //          system.assert(hp1.approvalstatus__c=='审批通过但未生效',hp1.approvalstatus__c);
           // hp1.approvalstatus__c='审批通过';
           // update hp1;
   //         hp1=[select id,class__c from hospital__c where id=:hp1.id];
    //        system.assert(hp1.class__c=='关键',hp1.class__c);
            


            }
     }
}